<?php

namespace App\Observers;

use App\Models\Posts;
use App\Models\PostsCollects;

class PostsCollectObserver
{

    /**
     * 监听创建前事件.
     *
     * @param PostsCollects $model
     * @return void
     */
    public function creating(PostsCollects $model)
    {

    }

    /**
     * 监听创建事件.
     *
     * @param PostsCollects $model
     * @return void
     */
    public function created(PostsCollects $model)
    {
        Posts::where('id', $model->posts_id)->increment('collect_amount');
    }

    public function updating(PostsCollects $model)
    {

    }

    /**
     * 监听更新后事件.
     *
     * @param PostsCollects $model
     * @return void
     */
    public function updated(PostsCollects $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param PostsCollects $model
     * @return void
     */
    public function deleting(PostsCollects $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param PostsCollects $model
     * @return void
     */
    public function deleted(PostsCollects $model)
    {
        Posts::where('id', $model->posts_id)->decrement('collect_amount');
    }

}
